﻿package mortal.game.manager.msgTip
{
    import com.gengine.utils.*;
    import flash.display.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.*;

    public class MsgGuideTipsImpl extends Sprite
    {
        private var _text:TextField;
        private var _timeKey:uint;

        public function MsgGuideTipsImpl()
        {
            cacheAsBitmap = true;
            mouseEnabled = false;
            mouseChildren = false;
            tabEnabled = false;
            return;
        }// end function

        private function initText() : void
        {
            this._text = new TextField();
            this._text.defaultTextFormat = new GTextFormat("", 14, 16160847, true, null, null, null, null, TextFormatAlign.LEFT);
            this._text.multiline = true;
            this._text.wordWrap = true;
            this._text.width = 200;
            this._text.x = 10;
            this._text.y = 10;
            this._text.filters = [FilterConst.nameGlowFilter];
            this._text.mouseEnabled = false;
            addChild(this._text);
            return;
        }// end function

        private function drawLineBox() : void
        {
            graphics.clear();
            graphics.lineStyle(1, 16160847);
            graphics.beginFill(0, 1);
            graphics.drawRect(0, 0, this._text.textWidth + 20, this._text.textHeight + 20);
            graphics.endFill();
            return;
        }// end function

        private function onTimeOut() : void
        {
            this.hide();
            return;
        }// end function

        public function show(param1:String, param2:int, param3:int, param4:DisplayObjectContainer = null, param5:int = 0) : void
        {
            if (!this._text)
            {
                this.initText();
            }
            if (param4 == null)
            {
                param4 = LayerManager.guideLayer;
            }
            this._text.htmlText = HTMLUtil.addColor(param1, "#F6984F");
            this.drawLineBox();
            this.x = param2;
            this.y = param3;
            param4.addChild(this);
            clearTimeout(this._timeKey);
            if (param5 > 0)
            {
                this._timeKey = setTimeout(this.onTimeOut, param5);
            }
            return;
        }// end function

        public function hide() : void
        {
            graphics.clear();
            clearTimeout(this._timeKey);
            if (this._text)
            {
                this._text.text = "";
            }
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            return;
        }// end function

    }
}
